
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>Ku8eye 登录</title>
  <!-- Tell the browser to be responsive to screen width -->
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  <!-- Bootstrap 3.3.5 -->
  <link rel="stylesheet" href="../bootstrap/css/bootstrap.min.css">
  <!-- Font Awesome -->
  <link rel="stylesheet" href="../css/font-awesome.min.css">
  <!-- Ionicons -->
  <link rel="stylesheet" href="../css/ionicons.min.css"> 
  <!-- Theme style -->
  <link rel="stylesheet" href="../css/AdminLTE.css">
  <!-- AdminLTE Skins. Choose a skin from the css/skins
       folder instead of downloading all of them to reduce the load. -->
  <link rel="stylesheet" href="../css/skins/skin-blue.min.css">
  <!-- Pace style -->
  <link rel="stylesheet" href="../plugins/pace/pace.min.css">
  
  <!-- DataTables -->
  <link rel="stylesheet" href="../plugins/datatables/dataTables.bootstrap.css">

  <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
  <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  <!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  <![endif]-->
</head>
<body class="hold-transition login-page">
<div class="login-box">
  <div class="login-logo">
    <a href="../index2.html">
    	<img src="./img/logo.png" style="height:80px;width:306px"/>
    </a>
  </div>
  <!-- /.login-logo -->
  <div class="login-box-body">
    <p class="login-box-msg">登录开启您的ku8 eye之旅</p>

    <form action="#">
      <div id="d_username" class="form-group has-feedback">
        <input id="username" type="email" class="form-control" placeholder="User Name">
        <span class="glyphicon glyphicon-envelope form-control-feedback"></span>
        <label class="control-label hide" for="inputError">
           <i class="fa fa-times-circle-o"></i>
           <span class="t_username">用户名不能为空</span>
        </label>
      </div>
      <div id="d_password" class="form-group has-feedback">
        <input id="password" type="password" class="form-control" placeholder="Password">
        <span class="glyphicon glyphicon-lock form-control-feedback"></span>
        <label class="control-label hide" for="inputError">
           <i class="fa fa-times-circle-o"></i>
           <span class="t_password"></span>
        </label>
      </div>
      <div class="row">
        <div class="col-xs-8">
          <div class="checkbox icheck">
            <label>
              <input type="checkbox"> 记住我
            </label>
          </div>
        </div>
        <!-- /.col -->
        <div class="col-xs-4">
          <button type="button" class="btn btn-primary btn-block btn-flat btnlogin">登&nbsp;录</button>
        </div>
        <!-- /.col -->
      </div>
    </form>
    
  </div>
  <!-- /.login-box-body -->
</div>
<!-- /.login-box -->

<!-- jQuery 2.1.4 -->
<script src="../plugins/jQuery/jQuery-2.1.4.min.js"></script>
<!-- Bootstrap 3.3.5 -->
<script src="../bootstrap/js/bootstrap.min.js"></script>
<!-- iCheck -->
<script src="../plugins/iCheck/icheck.min.js"></script>
<script>
  $(function () {
    $('input').iCheck({
      checkboxClass: 'icheckbox_square-blue',
      radioClass: 'iradio_square-blue',
      increaseArea: '20%' // optional
    });
    
    $('.btnlogin').click(function(){
    	login();
    });
    
    $('#username,#password').keypress(function (event){
    	if(event.keyCode==13){
    		login();
    	}
    });
  });
  
  function login(){
	  if(checkInput()){
  		$.post("/checklogin", {username:$('#username').val(),password:$('#password').val()},
  		   	    function(user){
  		   	    	if(user==null||user===''){
  		   	    		setErrorText("password","用户名或密码错误");
  		   	    	}else{
  		   	    		location.href="/index";
  		   	    	}
  		   	    });	
  	}
  }
  
  function checkInput(){
	  resetText();
	  if($("#username").val()===''){
		 setErrorText("username","用户名不能为空");
		 $("#username").focus();
		 return false;
	  }
	  if($("#password").val()===''){
		 setErrorText("password","密码不能为空");
		 $("#password").focus();
		 return false;
	  }
	  return true;
  }
  
  function setErrorText(stype,error){
	  if(stype==="username"){
		  $("#d_username > label").removeClass("hide");
		  $("#d_username").addClass("has-error");
		  $(".t_username").html(error);
	  }else if(stype==="password"){
		  $("#d_password > label").removeClass("hide");
		  $("#d_password").addClass("has-error");
		  $(".t_password").html(error);	
	  }
  }
  
  function  resetText(){
	  $("#d_username > label").addClass("hide");
	  $("#d_username").removeClass("has-error");
	  $("#d_password > label").addClass("hide");
	  $("#d_password").removeClass("has-error");
  }
</script>
</body>
</html>